const domainName = getApp().globalData.domainName
const parameter = getApp().globalData.parameter
// pages/doTi/do_records/do_records.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lis:[],
    page_no:0,
    page_size:10,
    no_more:false,
  },

  page_init(jg_stu_id, date_set, page_no, page_size){
    wx.request({
      url: domainName + '/do_records_init',
      data: {jg_stu_id, date_set, page_no, page_size},...parameter,
      success: res => {
        let lis = res.data.lis
        if(lis.length>0){
          this.setData({
            lis:this.data.lis.concat(lis),
            page_no:this.data.page_no+1
          })
        }else{
          this.setData({
            no_more:true
          })
        }
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.log('options',options)
    this.page_init(options.jg_stu_id, options.date_set, this.data.page_no, this.data.page_size)
    this.setData({
      jg_stu_id:options.jg_stu_id,
      date_set:options.date_set || '',
    })
    if(options.date_set){
      var title = '【' + options.date_set + '】做题记录'
    }else{
      var title = '累计做题记录'
    }
    wx.setNavigationBarTitle({title})
  },

  onReachBottom(){
    if(!this.data.no_more){
      if(this.data.page_no>5){
        wx.showModal({
          confirmText:'继续',
          cancelColor:'#00b050',
          content: '数据加载过多，可能导致手机卡顿',
          showCancel: true,
          title: '提醒',
          success: res => {
            this.page_init(this.data.jg_stu_id, this.data.date_set, this.data.page_no, this.data.page_size)
          },
        })
      }else{
        this.page_init(this.data.jg_stu_id, this.data.date_set, this.data.page_no, this.data.page_size)
      }
    }
  },

})